package top.wilsonlv.jaguar.cloud.websocket.sdk.dto;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

import java.io.Serializable;

/**
 * @author lvws
 * @since 2021/4/30
 */
@Data
public class WebsocketMessage implements Serializable {

    private String type;

    private JSONObject data;

    public WebsocketMessage() {
    }

    public WebsocketMessage(String type) {
        this.type = type;
    }

    public WebsocketMessage(String type, JSONObject data) {
        this.type = type;
        this.data = data;
    }

    public String toJsonString() {
        return JSONObject.toJSONString(this);
    }

    public WebsocketMessage setParam(String key, Serializable value) {
        if (this.data == null) {
            this.data = new JSONObject();
        }

        this.data.put(key, value);
        return this;
    }

}
